package com.syf.kit.core.ds.impl;

import cn.hutool.core.util.StrUtil;
import com.syf.kit.cont.RdsDSCont;
import com.syf.kit.enums.DataSourceType;
import com.syf.kit.enums.RDSType;

import javax.sql.DataSource;

public class SyfSingleDataSource implements SyfDataSource {
    private final RDSType rdsType;

    private final DataSource ds;

    public SyfSingleDataSource(RDSType rdsType, DataSource ds) {
        this.rdsType = rdsType;
        this.ds = ds;
    }

    @Override
    public RDSType getRDSType() {
        return rdsType;
    }

    @Override
    public DataSourceType getDsType() {
        return DataSourceType.SINGLE;
    }

    @Override
    public DataSource getDefaultDataSource() {
        return ds;
    }

    @Override
    public DataSource getDataSourceByName(String name) {
        if (StrUtil.equals(name, RdsDSCont.DEFAULT_DS_NAME)) {
            return ds;
        }

        throw new RuntimeException("SyfSingleDataSource只有一个数据源！");
    }
}
